"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const turf_1 = __importDefault(require("../../../ext/turf"));
function simplifyGeoJson(geoJson, bufferLength = 20) {
    let resGeoJson = turf_1.default.flatten(geoJson);
    while (resGeoJson.type === 'FeatureCollection' && resGeoJson.features.length > 5) {
        resGeoJson = turf_1.default.buffer(resGeoJson, bufferLength, { units: 'kilometers' });
        resGeoJson = turf_1.default.combine(resGeoJson);
        resGeoJson = turf_1.default.union(resGeoJson.features[0], resGeoJson.features[0]);
        resGeoJson = turf_1.default.flatten(resGeoJson);
    }
    resGeoJson = turf_1.default.simplify(resGeoJson, { tolerance: 0.1, highQuality: false });
    return resGeoJson;
}
exports.default = simplifyGeoJson;
